from django.shortcuts import render
from .models import Grades,Students

# Create your views here.
from django.http import HttpResponse


def index(request):
    return render(request, 'myapp/index.html')


# def detail(request,num):
#     return HttpResponse("detail-%s" %num)


def grades(request):
    # 去模板取数据
    gradesList = Grades.objects.all()
    return render(request, 'myapp/grades.html',
                  {"grades": gradesList})


def gradesID(request,num):
    # 获得对应班级对象
    grades = Grades.objects.get(pk=num)
    # 获得对应班级列表
    studentsList = grades.students_set.all()
    return render(request, 'myapp/students.html',
                  {'students': studentsList})


def students(request):
    studentsList = Students.objects.all()
    return render(request, 'myapp/students.html',
                  {"students": studentsList})
